<!-- 待报产工序 -->
<template>
	<view>
		<view class="header">
			<span>{{searchObj.deptName}}</span>
			<uv-tabs :list="list" @click="listClick"></uv-tabs>
		</view>
		<view class="header">
			<span>指令</span>
			<span class="blue">{{selectRow.lotNo}}</span>
			<span>缴库日期</span>
			<span class="blue">{{selectRow.slipDate}}</span>
			<span>类型</span>
			<span class="blue">{{selectType}}</span>
		</view>
		<view class="header">
			<uv-input v-model="number" placeholder="请输入序号"></uv-input>
			<uv-input v-model="progress" placeholder="请输入工序"></uv-input>
		</view>
		<view class="header">
			<button @click="search" class="button">搜索</button>
			<button @click="reset" class="buttonRS">重置</button>
		</view>


		<uni-table ref="table"  type="selection" border stripe emptyText="暂无更多数据" @selection-change="selectionChange">
			<!-- 表头行 -->
			<uni-tr>
				<uni-th :width="50" align="center">序号</uni-th>
				<uni-th :width="50" align="center">工序</uni-th>
				<uni-th :width="50" align="center">可报数</uni-th>
				<uni-th :width="50" align="center">录入</uni-th>
			</uni-tr>
			<!-- 表格数据行 -->
			<uni-tr v-for="item in tableList">
				<uni-td>{{item.seqNo}}</uni-td>
				<uni-td>{{item.processName}}</uni-td>
				<uni-td>{{item.qty3}}</uni-td>
				<uni-td>
					<view class="uni-group">
						<button class="uni-button" size="mini" type="primary" @tap="addOne(item)">修改</button>
					</view>
				</uni-td>
			</uni-tr>
		</uni-table>

		<uv-button class="btn" type="primary" text="道序合并报产" @click="combinedReport"></uv-button>

		<inputNum :show="userDialogShow" :tableData="selectList" :searchObj="searchObj"></inputNum>

		<uv-tabbar iconSize="30" :border="false" :value="tabbarValue" @change="tabbarChange">
			<uv-tabbar-item text="报产作业" icon="order"></uv-tabbar-item>
			<uv-tabbar-item text="产值查询" icon="search"></uv-tabbar-item>
			<uv-tabbar-item text="退出" icon="play-right"></uv-tabbar-item>
		</uv-tabbar>

		<uv-notify ref="notify" type="error"></uv-notify>
	</view>
</template>

<script>
	import inputNum from '@/components/inputNum/inputNum.vue'
	export default {
		data() {
			return {
				searchObj: {},
				selectType: '',
				selectRow: {}, //上个页面当前行
				tableList: [],
				tabbarValue: 0,
				userDialogShow: false,
				number: '',
				progress: '',
				searchList: [],
				list: [{
					name: '待报产工序',
				}, {
					name: '已报产工序',
				}],
				selectedIndexs: [],
				selectList: [],
			}
		},
		methods: {
			addOne(item) {
				this.userDialogShow = !this.userDialogShow
				item.addShow = true
				this.selectList = [item];
			},
			listClick(item) {
				if (item.name === '已报产工序') {
					uni.navigateTo({
						url: '/pages/reportedProductionProcess/reportedProductionProcess?tableList=' + JSON
							.stringify(this.tableList) + '&selectRow=' + JSON.stringify(this.selectRow) +
							'&searchObj=' + JSON.stringify(this.searchObj)
					})
				}
			},
			search() {
				this.getTableList();
			},
			// 道序合并报产按钮
			combinedReport() {
				const selectList = []
				for (let i = 0; i < this.selectedIndexs.length; i++) {
					selectList.push({
						...this.tableList[this.selectedIndexs[i]],
						addShow: false
					});
				}
				this.userDialogShow = !this.userDialogShow
				this.selectList = selectList
			},
			// 多选
			selectionChange(e) {
				this.selectedIndexs = e.detail.index
			},
			getTableList() {
				uni.request({
					url: '/kl/pad/stitchProductionReport/getNotReportProcessDetails',
					header: {
						'Authorization': uni.getStorageSync('token'), //自定义请求头信息
					},
					data: {
						...this.selectRow,
						seqNo: this.number,
						processName: this.progress,
					},
					method: "POST",
					success: (res) => {
						if (res.data.code === 200) {
							for (let i = 0; i < res.data.data.list.length; i++) {
								res.data.data.list[i].qty4 = res.data.data.list[i].qty3
							}
							this.tableList = res.data.data.list
							this.$refs.table.clearSelection()
							console.log(11111111111,this.$refs.table)
						} else {
							this.$refs.notify.show({
								message: res.data.message
							});
						}
					}
				});
			},
			reset() {
				this.number = ''
				this.progress = ''
			},
			tabbarChange(index) {
				this.tabbarValue = index
				if (index === 1) {
					uni.reLaunch({
						url: '/pages/outputSearch/outputSearch'
					})
				}
				if (index === 2) {
					uni.reLaunch({
						url: '/pages/login/login'
					})
				}
			},
		},
		onLoad(data) {
			// this.tableList = JSON.parse(data.selectList)
			this.selectRow = JSON.parse(data.selectRow)
			this.searchObj = JSON.parse(data.searchObj)
			this.selectType = this.selectRow.orderType2
			// this.selectRow.orderType === 0 ? this.selectType = '正单' : this.selectType = '补单'
			uni.$on('refresh', (data) => {
				this.getTableList()
			})
			this.getTableList()
		},
	}
</script>

<style>
	.header {
		padding: 10rpx 10rpx 10rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 26rpx;
	}

	.blue {
		color: #629BC9;
	}

	.uni-group {
		display: flex;
		align-items: center;
	}

	.btn {
		margin: 30rpx;
	}

	.uni-button {
		background: #007aff !important;
	}
</style>